#ifndef EZVOICEPLAYER_H
#define EZVOICEPLAYER_H

#include <QObject>
#include <QMediaPlayer>
#include "EZVoicePlayerDefin.h"
#include "EZTallyObject.h"

class SongModel;

class EZVoicePlayer : public QObject
{
    Q_OBJECT
public:
    static EZVoicePlayer* defaultPlayer();
public:
    explicit EZVoicePlayer(QObject *parent = 0);
    ~EZVoicePlayer();

    void playSong(SongModel *song);
    void play();
    void pause();
    void stop();
    void playOrPause();

    qint64 duration();
    qint64 currentTime();
    void setCurrentTime(qint64 time);
    int volume();

    SongModel* getSong();
private:
    QMediaPlayer mediaPlayer;

    SongModel *song;
    void setSong(SongModel *song);

    EZVoiceState state;
    friend class QMediaPlayer;

    void setPlayState(EZVoiceState);

    EZVoiceState MediaBufferStateToMyMediaState(QMediaPlayer::MediaStatus);
signals:
    void sigstateChanged(EZVoiceState);
private slots:
    void onStateChanged(QMediaPlayer::State mstate);
    void onBufferStatusChanged(int percentFilled);
    void onMediaStateChange(QMediaPlayer::MediaStatus status);

    void OnSongGetUrl(QString &key,int error);
public slots:
    void setVolume(int volume);

};

#endif // EZVOICEPLAYER_H
